#ifndef MATCHINGDATA_H
#define MATCHINGDATA_H

#include <plib.h>

#define MAX_GRAPHS 	30 /* maximum number of graph that can be put into
			      memory before generating an error */

/* parameter to get multiple graph data */
#define DEGREE 		1
#define WEIGHT 		2
#define CUTEDGE 	3
#define IMBALANCE 	4
#define NB_VERTICES 	5
#define NB_EDGES 	6
#define E_WEIGHT	7

#define MIN 		1
#define MAXI 		2
#define AVG 		3
#define STDDEV 		4
#define SUM 		5
#define IM              6

#define R_CUTEDGE	1
#define R_TCC		2
#define R_IMBALANCE	3
#define R_MET		4
#define R_MET025	5
#define R_MET05		6
#define R_MET1		7
#define R_MET2		8
#define R_TOTET		9
#define R_IMBET		10

#define R_PROVW		1
#define R_PROET		2

struct graph{
  int tool;
  int levels;
  int CType;
  int WType;
  int RType;
  int CSeed;
  int ISeed;
  int RSeed;
  char *F_graph;
  char *F_grid;
  PlotGraphType *graph;
  PlotGridType *grid;
};
typedef struct graph Graph;

struct statvalues{
  double sum;
  double min;
  double max;
  double avg;
  double stddev;
};
typedef struct statvalues StatValues;

struct statinidef{
  int ids;
  struct statvalues* data;
  struct statvalues* degree;
  struct statvalues* cutedge;
  struct statvalues* weight;
  struct statvalues* eweight;
  double *imbalance;
};
typedef struct statinidef StatIniType;

struct statdef{
  int levels;
  char* scheme;
  char* filename;
  struct statvalues* data;
  int *nb_edges;
  int *nb_vertices;
  struct statvalues* degree;
  struct statvalues* cutedge;
  struct statvalues* weight;
  struct statvalues* eweight;

  /* initial partitioning stored by id*/
  StatIniType* ini;
};
typedef struct statdef StatType;


struct levelrefine{
  int levels;
  double* data; // for mem allocation

  int nparts;
  double*  cutedge;
  double*  tcc;
  double*  imbalance;
  double*  met[5];
  double** exec;		/* exec[level][pro] */
  struct statvalues* proVW;
  struct statvalues* proET;     /* imbalance and other things easy to get */  
};

typedef struct levelrefine RefineStats;

RefineStats** MD_readRefineStats(char**,int*,int*,char *, int,Graph ***);
RefineStats* MD_readRefineStat(char* matching,int where,char *base,Graph **store_g);
double* MD_getRefineData(RefineStats* s,int x,int x_stat,int x_value,int x_type);

StatType** MD_readStats(char **files,int nb,Graph ***g,int **ids,char* F_graph,char* F_grid);
Graph** MD_getGraphsRefine(char** matchings,int* m_ids,int* w_ids,int *ids,
			   char *base,int nb);
Graph** MD_getGraphs(char** matchings,int* ids,int nb);
double* MD_getLevelData(StatType *s,int type,int value,int id);
double* MD_getDataArray(StatType **,int,int,int);
double* MD_getIniDataArray(StatType **s,int size,int type,int value,int* ids);
int MD_printMatchingStats(StatType *s,FILE* fp,int id);
double** MD_getGraphData(Graph *,int type,char *matching,char ***plot_names,int *);
StatIniType* MD_StatIniAlloc(int **ids,int nb);
int MD_BestByMethod(StatIniType* s,int value,int type,int minmax,double *val,int *id);


void MD_freeGraph(Graph *g);
void MD_free(StatType *);
void MD_freeArr(StatType **,int);
void MD_freeI(StatIniType *s);
void MD_freeR(RefineStats *);
void MD_freeArrR(RefineStats **,int);

#endif
